package com.media.dao.impl;

import com.media.bean.UserBean;
import com.media.dao.UserDao;
import com.media.util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class UserDaoImpl implements UserDao {
    @Override
    public UserBean getUserById(int id) throws SQLException {

        UserBean user = null;
        
            Connection connection = DBUtil.getConnection();

            //sql 模板
            String sql = "select * from user where id = ?";

            //使用PreparedStatement对象执行sql语句
            PreparedStatement ps = connection.prepareStatement(sql);

            ps.setInt(1,id);

            ResultSet rs = ps.executeQuery();

            if(rs.next()){
                user = new UserBean();
                user.setUsername(rs.getString("username"));
                //...
            }

        return user;
    }

    @Override
    public List<UserBean> getUserList() {
        return null;
    }

    @Override
    public boolean AddUser() {
        return false;
    }

    @Override
    public boolean EditUser() {
        return false;
    }

    @Override
    public boolean DeleteUser() {
        return false;
    }
}
